import { login, Profile, ProfileMore } from '@/api'
import { getToken, setToken } from '@/utils/auth.js'
export default {
  namespaced: true,
  state: {
    token: getToken() || '',
    user: {}
  },
  mutations: {
    SET_TOKEN(state, token) {
      state.token = token
      setToken(token)
    },
    SET_PROFILE(state, data) {
      state.user = data
      console.log(state.user)
    }
  },
  actions: {
    async loginRequest(store, loginFrom) {
      const { data } = await login(loginFrom)
      store.commit('SET_TOKEN', data)
    },
    async profile(store) {
      const res = await Profile()
      const res1 = await ProfileMore(res.data.userId)
      store.commit('SET_PROFILE', { ...res.data, ...res1.data })
    }
  }
}
